package com.todo.biz.application.handler.review.content;

import com.alibaba.fastjson.JSONObject;
import com.todo.biz.application.entity.context.ContentReviewContext;
import com.todo.biz.application.entity.context.ContentReviewResult;
import com.todo.biz.application.entity.enums.ContentReviewEnum;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.exception.BizException;
import lombok.extern.slf4j.Slf4j;

/**
 * @author azhebuxing
 * @date 2024/6/12 14:09
 * @description
 */
@Slf4j
public abstract class AbstractContentReview {

    public ContentReviewResult contentReviewHandle(ContentReviewContext context) {
        if (context == null) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        try {
            if (match(context)) {
                ContentReviewResult contentReviewResult = doHandle(context);
                return contentReviewResult;
            }
        } catch (Exception ex) {
            log.error("AbstractContentReview#contentReviewHandle 文字内容审核遇到异常，数据处理失败，默认失败 context:{}", JSONObject.toJSONString(context), ex);
        }
        ContentReviewResult result = new ContentReviewResult();
        result.setReviewResult(false);
        return result;
    }

    /**
     * 是否需要处理
     *
     * @param context
     * @return
     */
    protected abstract Boolean match(ContentReviewContext context);

    /**
     * 具体处理逻辑
     *
     * @param context
     * @return
     */
    protected abstract ContentReviewResult doHandle(ContentReviewContext context);

    /**
     * 当前处理类
     *
     * @return
     */
    protected abstract ContentReviewEnum getContentReviewEnum();
}
